/*
 * Parser.java
 *
 * Created on December 12, 2007, 12:45 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.fie.parser;

import java.io.IOException;
import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.Element;
import nu.xom.ParentNode;
import nu.xom.ParsingException;
import soaptwo.StockQuote;

/**
 *
 * @author joseacuna-rohter
 */
public class Parser {
    
    /**
     * Creates a new instance of Parser
     */

    private Element e;
    private Element p;
    
    public  Parser(String ticker){
        
    try {
      String theXML;
      Builder parser = new Builder();
      StockQuote sqp = new StockQuote();
      theXML = sqp.getStockQuoteSoap().getQuote(ticker);
      
      ParentNode p;
      
      
      Document doc = parser.build(theXML,null);
      e = doc.getRootElement();
      e = e.getFirstChildElement("Stock");
      System.out.println(e.getValue());
      }
        catch (ParsingException ex) {
          System.err.println("Cafe con Leche is malformed today. How embarrassing!");
        }
        catch (IOException ex) {
          System.err.println("Could not connect to Cafe con Leche. The site may be down.");
        }
        
    }
    
    
    public String getLast(){
        p = e.getFirstChildElement("Last");
        return p.getValue();
    }
    
    public String getName(){
        p = e.getFirstChildElement("Name");
        return p.getValue();
    }
    
    public String getLastTime(){
        p = e.getFirstChildElement("Time");
        return p.getValue();
    }
    
    public String getPercentChange(){
        p = e.getFirstChildElement("PercentageChange");
        return p.getValue();
        
    }
    
    
}
